<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>${_title}</title>

    <!-- Bootstrap core CSS -->

    <link href="${_css}/bootstrap.min.css" rel="stylesheet">

    <link href="${_font}/css/font-awesome.min.css" rel="stylesheet">
    <link href="${_css}/animate.min.css" rel="stylesheet">

    <!-- Custom styling plus plugins -->
    <link href="${_css}/custom.css" rel="stylesheet">
    <link href="${_css}/icheck/flat/green.css" rel="stylesheet">
    <link href="${_css}/datatables/tools/css/dataTables.tableTools.css" rel="stylesheet">
    <link rel="stylesheet" href="${_css}/base.css">
    <script src="${_js}/jquery.min.js"></script>
    <script type="text/javascript" src="${_front_js}/jquery.page.js"></script>
    <script src="${_js}/resize.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
	<style>
		td a{
			cursor:pointer
		}
	</style>
</head>

<body style="background: #F7F7F7;">
<div class="">
    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
	                <div class="x_title">
	                    <h2>用户列表</h2>
	                    <div class="clearfix"></div>
	                </div>
	                
                    <div class="pull-right">
                    	<button id="query" type="button" class="btn btn-info">查询</button>
                    	<!--<button id="send" type="button" class="btn btn-success" data-toggle="modal" data-target=".add-user">手动注册</button> -->
                    </div>
                    <form class="form-horizontal form-label-left input_mask" style="margin-left: -10px;">
                        <div class="col-md-2 col-sm-2 col-xs-6 form-group has-feedback">
                            <input type="text" class="form-control has-feedback-left" id="username" value="<#if userName?exists>${userName}</#if>"
                            placeholder="输入用户名">
                            <span class="fa fa-user form-control-feedback left" aria-hidden="true"></span>
                        </div>
                        <div class="col-md-2 col-sm-2 col-xs-6 form-group has-feedback">
                            <input type="text" class="form-control has-feedback-left" id="phone" value="<#if phone?exists>${phone}</#if>"
                            placeholder="输入手机号 ">
                            <span class="fa fa-user form-control-feedback left" aria-hidden="true"></span>
                        </div>
                        <form class="form-horizontal">
								<div class="control-group">
									<div class="controls">
										<div class="input-prepend input-group">
											<span class="add-on input-group-addon">
												<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
											</span>
											<input type="text" style="width: 200px" name="reservation" id="reservation" placeholder="请选择用户注册时间段"
											class="form-control" value="" />
										</div>
									</div>
								</div>
						</form>
                     </form>
                    <div class="clearfix"></div>
                </div>
                <div class="scroll">
                <div class="x_content">
                    <table id="example" data-action="/admin/userinfo/list?1=1" class="table table-striped responsive-utilities jambo_table">
                    <input type="hidden" id="userId">
                        <thead>
                            <tr class="headings">
                                <th>
                                    <input type="checkbox" class="tableflat">
                                </th>
                                <th>用户ID</th>
                                <th>用户名</th>
                                <th>手机号 </th>
                                <th>真实姓名 </th>
                                <th>身份证号码</th>
                                <th>开户省市 </th>
                                <th>开户行名称</th>
                                <th>银行卡号</th>
                                <th>银行卡更改时间 </th>
                                <th>上次登录时间 </th>
                                <th class="no-link last">
                                	<span class="nobr">操作</span>
                                </th>
                            </tr>
                        </thead>

                        <tbody>
			                <#if (pageInfo?exists && pageInfo.pageList?size > 0)>
								<#list pageInfo.pageList as item>
									<tr class="even pointer">
		                                <td class="a-center ">
		                                    <input type="checkbox" class="tableflat">
		                                </td>
		                                <td>
		                                	${item.uid}
		                                </td>
		                                <td>
		                                 <#if item.userName?exists>
		                                	${item.userName}
		                                 </#if>
		                                </td>
		                                <td>
		                                  <#if item.phone?exists>
		                                	${item.phone}
		                                	<#else>
		                                	</#if>
		                                </td>		                                
		                                <td>
		                                  <#if item.realName?exists>
		                                	${item.realName!}
		                                	<#else>
		                                 </#if>
		                                </td>
		                                <td>
		                                  <#if item.certId?exists>
		                                	${item.certId!}
		                                	<#else>
		                                 </#if>
		                                </td>								
		                                <td>
		                                 <#if item.province?exists>
		                                	${item.province!}
		                                	<#else>
		                                 </#if>
		                                </td>
		                                <td>
		                                  <#if item.bankName?exists>
		                                	${item.bankName!}
		                                	<#else>
		                                 </#if>
		                                </td>								
		                                <td>
		                                  <#if item.cardNo?exists>
		                                	${item.cardNo!}
		                                	<#else>
		                                  </#if>
		                                </td>
		                                <td>
		                                <#if item.createTime?exists>
		                                	${item.createTime}
		                                </#if>
		                                </td>
		                                <td>
		                                <#if item.lastTime?exists>
		                                	${item.lastTime}
		                                 </#if>
		                                </td>
		                                <td class="last">
		                            		<a href="#" class="user-inviteCode" data-toggle="modal" data_action="/admin/userinfo/querylist"  data-target=".add-user-inviteCode" id="${item.uid}">编辑</a>  
		                                </td>
		                             </tr>   
		                        </#list>
		                        <#else>
								<tr class="even pointer">
									<td colspan="11">无记录</td>
								</tr>
							</#if>
                        </tbody>
                    </table>
                    <#if (pageInfo.pageList?size > 0)>
	                	<#include "../base/Page.ftl">
	                </#if>
                </div>
                </div>
            </div>
        <br />
    </div>
</div>


<!--新增用户 -->
<div class="modal fade bs-example-modal-sm add-user" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm about-bank">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" id="myModalLabel2">手动注册</h4>
            </div>
            <div class="modal-body">
                 <form class="form-horizontal form-label-left" novalidate>
					<div class="item form-group">
                        <label class="control-label col-md-4 col-sm-4 col-xs-12" for="name">用户名
                        </label>
                        <div class="col-md-8 col-sm-8 col-xs-12">
                            <input id="form_username" class="form-control col-md-8 col-xs-12" type="text">
                        </label>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-4 col-sm-4 col-xs-12" for="name">手机号码
                        </label>
                        <div class="col-md-8 col-sm-8 col-xs-12">
                            <input id="form_phone" class="form-control col-md-7 col-xs-12" type="text"
                            onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                            >
                        </label>
                        </div>
                    </div>                                      
                    <div class="item form-group">
                        <label class="control-label col-md-4 col-sm-4 col-xs-12" for="name">密码
                        </label>
                        <div class="col-md-8 col-sm-8 col-xs-12">
                            <input type="password" id="form_pwd" class="form-control col-md-7 col-xs-12" type="text">
                        </label>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-4 col-sm-4 col-xs-12" for="name">确认密码
                        </label>
                        <div class="col-md-8 col-sm-8 col-xs-12">
                            <input type="password" id="form_re-pwd" class="form-control col-md-7 col-xs-12" type="text">
                        </label>
                        </div>
                    </div>
                 </form>   
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary check-submit user-submit">提交</button>
            </div>
        </div>
    </div>
</div>

<!--新增内部邀请码 -->
<!--<div class="modal fade bs-example-modal-sm add-user-inviteCode" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm about-bank">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" id="myModalLabel2">设置邀请码</h4>
            </div>
            <div class="modal-body">
                 <form class="form-horizontal form-label-left" novalidate>
					<div class="item form-group">
                        <label class="control-label col-md-4 col-sm-4 col-xs-12" for="insideInviteCode">邀请码
                        </label>
                        <div class="col-md-8 col-sm-8 col-xs-12">
                            <input id="insideInviteCode" class="form-control col-md-8 col-xs-12" type="text" maxlength="11">
                        </label>
                        </div>
                    </div>
                 </form>   
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary check-submit user-inviteCode-submit">提交</button>
            </div>
        </div>
    </div>
</div>-->
 
<script src="${_js}/bootstrap.min.js"></script>

<!-- bootstrap progress js -->
<script src="${_js}/progressbar/bootstrap-progressbar.min.js" type="text/javascript"></script>
<script src="${_js}/nicescroll/jquery.nicescroll.min.js" type="text/javascript"></script>
<!-- icheck -->
<script src="${_js}/icheck/icheck.min.js" type="text/javascript"></script>
<script src="${_js}/custom.js" type="text/javascript"></script>

<!-- PNotify -->
<script src="${_js}/notify/pnotify.core.js" type="text/javascript"></script>
<script src="${_js}/notify/pnotify.buttons.js" type="text/javascript"></script>
<script src="${_js}/notify/pnotify.nonblock.js" type="text/javascript" ></script>

<!-- daterangepicker -->
<script type="text/javascript" src="${_js}/datepicker/moment.min2.js"></script>
<script type="text/javascript" src="${_js}/datepicker/daterangepicker.js"></script>
<script type="text/javascript" src="${_front_js}/date.js"></script>
<script type="text/javascript" src="${_front_js}/layer/layer.js"></script>
<script type="text/javascript">

		//加载扩展模块
		layer.config({
		    extend: 'extend/layer.ext.js'
		});
		
    $(document).ready(function () {
    	//var nowDate = new Date();
    	//var year = formatYearDate(nowDate);
    	//var month = formatMonthDate(nowDate);
    	//var day = formatDayDate(nowDate);
    	//$("#reservation").attr("value","12/01/2015 - "+month+"/"+day+"/"+year);
        $('#reservation').daterangepicker(null, function (start, end, label) {
            //console.log(start.toISOString(), end.toISOString(), label);
        });
    });
</script>

<script type="text/javascript">
    $(document).ready(function(){
        $('input.tableflat').iCheck({
            checkboxClass: 'icheckbox_flat-green',
            radioClass: 'iradio_flat-green'
        });
    });
    $(".user-inviteCode").click(function(){
    	var uid = $(this).attr("id");
    	$("#userId").attr("value",userId);
    	var action=$(this).attr("data_action");
    	if(uid!=""){
    	  action+="?uid="+uid;
    	}
	    window.location.href=action;	
    });
    
    function initData(action) { 
    	var username = $.trim($("#username").val());
    	var realname = $.trim($("#realname").val());
    	var phone = $.trim($("#phone").val());
    	var reservation = $("#reservation").val();
    	var reg = /^\d{4}[-]\d{2}[-]\d{2}~\d{4}[-]\d{2}[-]\d{2}$/;
		if(reservation !="" && !reg.test(reservation)){
			new PNotify({
		            	title: '操作提示',
		            	text: '时间格式错误！',
		            	delay: 3e3,
		            	type: 'error'
		        	});
		    return false;
		}
    	if(username != ""){
    		action += "&username="+username;
    	}
    	if(realname != ""){
    		action += "&realname="+realname;
    	}
    	if(phone != ""){
    		action += "&phone="+phone;
    	}
    	if(reservation !=""){
    		var splitChar = "~";
    		if(reservation.indexOf(splitChar) != -1){
    			var sendTimeFrom = reservation.split(splitChar)[0].trim();
    			var sendTimeTo = reservation.split(splitChar)[1].trim();
    			action += "&sendTimeFrom="+sendTimeFrom;
    			action += "&sendTimeTo="+sendTimeTo;
    		}
    	}
		window.location.href=encodeURI(encodeURI(action));
	} 
	
	$(".btn-info").click(function(){
		initData($("#example").attr('data-action'));
	});
	
	$(".user_ref").click(function(){
    	var userId = $(this).attr("id");
    	$("#userId").attr("value",userId);
    });
    
	$(".user_ref_submit").click(function(){
		var inviteUser=$("#inviteUser").val();
		var id=$("#userId").val();
		debugger;
		$.ajax({
            type: "POST",
			datatype:"json",
            url: '/admin/user/ref',
            data:{
            	id:id,
            	username:inviteUser
            },
            async: false,
            success: function(result){
            	if(result.code==-1){
            		alert("设置成功!");
            		window.location.reload();
            	}else{
            		alert(result.msg);
            	}
            }
        });
	})
	
	$(".user_login").click(function(){
    	var userId = $(this).attr("id");
    	$.ajax({
            type: "POST",
			datatype:"json",
            url: '/admin/sim/login',
            data:{
            	userId:userId
            },
            async: false,
            success: function(result){
            	if(result.code==-1){
            		layer.alert(result.msg, function(index){
				    layer.close(index);
            			window.open("/account/info");
            		});
            	}
            }
        });
    });
    
    //删除用户
    var userId;
    $('.user_delete').click(function(){
    	userId = $(this).attr("id");
    });
    
    $('.delete-user-submit').click(function(){
    	$.ajax({
            type: 'POST',
            dataType: 'JSON',
            async:'false',
            url: '/admin/user/delete',
            data: {"userId":userId},
            success: function(result){
       			if(result.code == -1){
       				new PNotify({
		            	title: '操作提示',
		            	text:  result.msg,
		            	delay: 3e3,
		            	type: 'success'
		        	});
		        	$(".btn-info").click();//刷新页面
       			}else{
       				new PNotify({
		            	title: '操作提示',
		            	text:  result.msg,
		            	delay: 3e3,
		            	type: 'error'
		        	});
       			}
          	}
	    })	
    });
    
    
    var regTimeFrom = "<#if sendTimeFrom?exists>${sendTimeFrom}</#if>";
    var regTimeTo = "<#if sendTimeTo?exists>${sendTimeTo}</#if>";
    if(regTimeFrom != "" && regTimeTo != ""){
    	document.getElementById("reservation").value=regTimeFrom+"~"+regTimeTo;
    }
</script>

</body>

</html>